package com.pcbly.web.persistence.chart;


import java.util.List;

import com.pcbly.web.bean.chart.ChartBean;
import com.pcbly.web.bean.chart.ChartStyleBean;
import com.pcbly.web.bean.chart.ChartStyleCoordinateBean;
import com.pcbly.web.bean.chart.ChartStyleLineBean;
import com.pcbly.web.bean.chart.ChartStyleTextBean;
import com.pcbly.web.persistence.HibernateBaseDao;

public class ChartHibernateDao extends HibernateBaseDao<ChartBean> implements
		ChartDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = -41064260234414502L;
	public ChartHibernateDao(){
		super();
	}
	protected Class<ChartBean> getEntityClass() {
		return ChartBean.class;
	}
	@Override
	public ChartBean queryDetailChartBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		ChartBean chart=super.get(entityClass, id);
		
		chart.setStyle(getStyleById(chart.getStyle().getId()));
		
		chart.setTitleStyle(getStyleTextById(chart.getTitleStyle().getId()));
		
		chart.setDescStyle(getStyleTextById(chart.getDescStyle().getId()));
		
		chart.setBorderStyle(getStyleLineById(chart.getBorderStyle().getId()));
		
		chart.setCutlineBorderStyle(getStyleLineById(chart.getCutlineBorderStyle().getId()));
		
		chart.setCutlineTextStyle(getStyleTextById(chart.getCutlineTextStyle().getId()));
		
		chart.setCoordinateStyle(getStyleCoordinateById(chart.getCoordinateStyle().getId()));
		
		chart.setCoordinatexTextStyle(getStyleTextById(chart.getCoordinatexTextStyle().getId()));
		
		chart.setCoordinateyTextStyle(getStyleTextById(chart.getCoordinateyTextStyle().getId()));
		
		chart.setColumnTextStyle(getStyleTextById(chart.getColumnTextStyle().getId()));
		
		return chart;
	}
	
	public ChartBean queryChartBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		
		return super.get(entityClass, id);
	}
	@Override
	public int deleteChartBean(String id) throws Exception {
		// TODO Auto-generated method stub
//		ChartBean bean=super.get(entityClass, id);
		super.removeById(entityClass, id);
		return 1;
	}
	@Override
	public int insertChartBean(ChartBean chartBean) throws Exception {
		// TODO Auto-generated method stub
		getHibernateTemplate().save(chartBean);
		return 1;
	}
	@Override
	public int updateChartBean(ChartBean chartBean) throws Exception {
		// TODO Auto-generated method stub
		getHibernateTemplate().update(chartBean);
		return 1;
	}
	protected ChartStyleCoordinateBean getStyleCoordinateById(String id)throws Exception{
		Object o=getHibernateTemplate().find("from ChartStyleCoordinateBean where id=?", id);
		return (ChartStyleCoordinateBean)o;
	}
	
	protected ChartStyleTextBean getStyleTextById(String id)throws Exception{
		Object o=getHibernateTemplate().find("from ChartStyleTextBean where id=?", id);
		return (ChartStyleTextBean)o;
	}
	protected ChartStyleBean getStyleById(String id)throws Exception{
		Object o=getHibernateTemplate().find("from ChartStyleBean where id=?", id);
		return (ChartStyleBean)o;
	}
	protected ChartStyleLineBean getStyleLineById(String id)throws Exception{
		Object o=getHibernateTemplate().find("from ChartStyleLineBean where id=?", id);
		return (ChartStyleLineBean)o;
	}
	@Override
	public List<ChartBean> queryList() throws Exception {
		// TODO Auto-generated method stub
		return super.getAll(entityClass);
	}


}
